package com.ruoyi.project.system.record.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.baseinfo.domain.TNewbornBaseinfo;
import com.ruoyi.project.system.baseinfo.service.ITNewbornBaseinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.record.mapper.TDiseaseRecordMapper;
import com.ruoyi.project.system.record.domain.TDiseaseRecord;
import com.ruoyi.project.system.record.service.ITDiseaseRecordService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 新生儿疾病记录Service业务层处理
 *
 * @author
 * @date 2021-03-31
 */
@Service
public class TDiseaseRecordServiceImpl implements ITDiseaseRecordService
{
    @Autowired
    private TDiseaseRecordMapper tDiseaseRecordMapper;

    @Autowired
    private ITNewbornBaseinfoService itNewbornBaseinfoService;

    /**
     * 查询新生儿疾病记录
     *
     * @param id 新生儿疾病记录ID
     * @return 新生儿疾病记录
     */
    @Override
    public TDiseaseRecord selectTDiseaseRecordById(Long id)
    {
        return tDiseaseRecordMapper.selectTDiseaseRecordById(id);
    }

    /**
     * 查询新生儿疾病记录列表
     *
     * @param tDiseaseRecord 新生儿疾病记录
     * @return 新生儿疾病记录
     */
    @Override
    public List<TDiseaseRecord> selectTDiseaseRecordList(TDiseaseRecord tDiseaseRecord)
    {
        return tDiseaseRecordMapper.selectTDiseaseRecordList(tDiseaseRecord);
    }

    /**
     * 新增新生儿疾病记录
     *
     * @param tDiseaseRecord 新生儿疾病记录
     * @return 结果
     */
    @Override
    public int insertTDiseaseRecord(TDiseaseRecord tDiseaseRecord)
    {
        tDiseaseRecord.setCreateTime(DateUtils.getNowDate());
        return tDiseaseRecordMapper.insertTDiseaseRecord(tDiseaseRecord);
    }

    /**
     * 修改新生儿疾病记录
     *
     * @param tDiseaseRecord 新生儿疾病记录
     * @return 结果
     */
    @Override
    public int updateTDiseaseRecord(TDiseaseRecord tDiseaseRecord)
    {
        tDiseaseRecord.setUpdateTime(DateUtils.getNowDate());
        return tDiseaseRecordMapper.updateTDiseaseRecord(tDiseaseRecord);
    }

    /**
     * 删除新生儿疾病记录对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTDiseaseRecordByIds(String ids)
    {
        return tDiseaseRecordMapper.deleteTDiseaseRecordByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除新生儿疾病记录信息
     *
     * @param id 新生儿疾病记录ID
     * @return 结果
     */
    @Override
    public int deleteTDiseaseRecordById(Long id)
    {
        return tDiseaseRecordMapper.deleteTDiseaseRecordById(id);
    }

    /**
     * 查询新生儿待治疗和治疗中疾病记录列表
     * @param tDiseaseRecord
     * @return
     */
    @Override
    public List<TDiseaseRecord> selectTDiseaseInTreatRecordList(TDiseaseRecord tDiseaseRecord) {
        return tDiseaseRecordMapper.selectTDiseaseInTreatRecordList(tDiseaseRecord);
    }

    /**
     * 新生儿疾病结束治疗
     * @param tDiseaseRecord
     * @return
     */
    @Override
    public int stop(TDiseaseRecord tDiseaseRecord) {
        TDiseaseRecord diseaseRecord = tDiseaseRecordMapper.selectTDiseaseRecordById(tDiseaseRecord.getId());
        diseaseRecord.setStatus(4);
        diseaseRecord.setUpdateTime(new Date());
        TNewbornBaseinfo tNewbornBaseinfo = itNewbornBaseinfoService.selectTNewbornBaseinfoById(diseaseRecord.getNewbornId());
        tNewbornBaseinfo.setStatus(5);
        itNewbornBaseinfoService.updateTNewbornBaseinfo(tNewbornBaseinfo);
        return tDiseaseRecordMapper.updateTDiseaseRecord(diseaseRecord);
    }
}
